{extend name="base"/}
{block name="resources"}
<style  type="text/css">
    .form-group{
        width: 100%;
    }
</style>
{/block}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="javascript:;" class="n_tab_list">添加打印机</a>
        </div>
        <div class="panel mb-3" id="app">
            <div class="panel-body">
                <form class="auto-form" method="post" id="form">
                    <input type="hidden" value="{$pid}" name="pid">
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                            <label class="col-form-label required">打印机名称</label>
                        </div>
                        <div class="col-sm-6">
                            <input class="form-control" name="name" value="{$model['name']}">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                            <label class="col-form-label">打印机类型</label>
                        </div>
                        <div class="col-sm-6">
                            <select class="form-control" name="printer_type" v-model="printer_type">
                                <option value="kdt2">365云打印（编号kdt2）</option>
                                <option value="yilianyun-k4">易联云（k4）</option>
                                <option value="feie">飞鹅打印机</option>
                            </select>
                            <div class="text-muted fs-sm">目前支持365-kdt2云打印、易联云-k4、飞鹅打印机</div>
                        </div>
                    </div>
                    <div v-if="printer_type == 'kdt2'">
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印机编号</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[name]"
                                       value="{$model['printer_setting']['name']}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印机密钥</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[key]"
                                       value="{$model['printer_setting']['key']}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印机联数</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" type="number" min="1" max="9" name="printer_setting[time]"
                                       value="{$model['printer_setting']['time']}">
                                <div class="text-muted fs-sm">同一订单，打印的次数</div>
                            </div>
                        </div>
                        <div class="form-group row" style="display: none;">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">URL</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[url]"
                                       value="http://open.printcenter.cn:8080/addOrder">
                            </div>
                        </div>
                    </div>
                    <div v-if="printer_type == 'yilianyun-k4'">
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">终端号</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[machine_code]"
                                       value="{$model['printer_setting']['machine_code']}">
                                <div class="text-muted fs-sm">打印机终端号</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">密钥</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[key]"
                                       value="{$model['printer_setting']['key']}">
                                <div class="text-muted fs-sm">打印机终端密钥</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">用户ID</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[client_id]"
                                       value="{$model['printer_setting']['client_id']}">
                                <div class="text-muted fs-sm">用户id（管理中心系统集成里获取）</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">apiKey</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[client_key]"
                                       value="{$model['printer_setting']['client_key']}">
                                <div class="text-muted fs-sm">apiKey（管理中心系统集成里获取）</div>
                            </div>
                        </div>
                        <div class="form-group row" style="display: none;">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">URL</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[url]"
                                       value="<?= !empty($model['printer_setting']['url']) ? $model['printer_setting']['url'] : "http://open.10ss.net:8888" ?>">
                                <div class="text-muted fs-sm">API接口地址</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印联数</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" type="number" min="1" max="9" name="printer_setting[time]"
                                       value="{$model['printer_setting']['time']}">
                                <div class="text-muted fs-sm">同一订单，打印的次数</div>
                            </div>
                        </div>
                    </div>
                    <div v-if="printer_type == 'feie'">
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">USER</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[user]"
                                       value="{$model['printer_setting']['user']}">
                                <div class="text-muted fs-sm">飞鹅云后台注册用户名</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">UKEY</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[ukey]"
                                       value="{$model['printer_setting']['ukey']}">
                                <div class="text-muted fs-sm">飞鹅云后台登录生成的UKEY</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印机编号</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[sn]"
                                       value="{$model['printer_setting']['sn']}">
                                <div class="text-muted fs-sm">打印机编号9位,查看飞鹅打印机底部贴纸上面的打印机编号</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印机key</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="printer_setting[key]"
                                       value="{$model['printer_setting']['key']}">
                                <div class="text-muted fs-sm">查看飞鹅打印机底部贴纸上面的打印机key</div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">打印联数</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" type="number" min="1" max="9" name="printer_setting[time]"
                                       value="{$model['printer_setting']['time']}">
                                <div class="text-muted fs-sm">同一订单，打印的次数</div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                            <label class="col-form-label">订单打印方式</label>
                        </div>
                        <div class="col-sm-6">
                            <label class="checkbox-label">
                                <input id="type_radio1"
                                       value="1" {if $model['when']['order'] == 1}checked{/if}
                                name="when[order]" type="checkbox" class="custom-control-input">
                                <span class="label-icon"></span>
                                <span class="label-text">下单打印</span>
                            </label>
                            <label class="checkbox-label">
                                <input id="type_radio2"
                                       value="1" {if $model['when']['pay'] == 1}checked{/if}
                                name="when[pay]" type="checkbox" class="custom-control-input">
                                <span class="label-icon"></span>
                                <span class="label-text">付款打印</span>
                            </label>
                            <label class="checkbox-label">
                                <input id="type_radio3"
                                       value="1" {if $model['when']['confirm'] == 1}checked{/if}
                                name="when[confirm]" type="checkbox" class="custom-control-input">
                                <span class="label-icon"></span>
                                <span class="label-text">确认收货打印</span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                        </div>
                        <div class="col-sm-6">
                            <button type="submit" class="btn btn-primary auto-form-btn" href="javascript:">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </article>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                printer_type: "<?=$model['printer_type'] ? $model['printer_type'] : "kdt2"?>",
            },
        });
        var flag = false;
        $("#form").on("submit",function () {
            if(flag){return};
            flag = true;
            $.ajax({
                url: "{:url('printer/editprinter')}",
                type: 'POST',
                cache: false,
                data: new FormData($('#form')[0]),
                processData: false,
                contentType: false,
                dataType: 'json',
                success:function (res) {
                    console.log(res);
                    flag = false;
                    if(res.code == 1)
                    {
                        layer.msg(res.message,{icon:1,time:1000},function () {
                            window.location.href = "{:url('printer/index')}";
                        });
                    }
                    else
                    {
                        layer.msg(res.message,{icon:5,time:1000});
                    }
                },
                error:function (err) {
                    console.log(err);
                    flag = false;
                }
            }).done(function(res) {
            }).fail(function(res) {
            });
            return false;
        });
    </script>
</div>
{/block}